package com.xinqi.modules.stats.score.controller.web;

import com.xinqi.common.base.response.R;
import com.xinqi.modules.stats.score.domain.CourseTotalScoreBaseConfigEntity;
import com.xinqi.modules.stats.score.dto.req.*;
import com.xinqi.modules.stats.score.dto.rsp.CourseTotalScoreConfigResultDTO;
import com.xinqi.modules.stats.score.service.CourseTotalScoreConfigService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 总成绩等级制分值配置WEB端
 *
 * @author: system
 * @date: 2023/03/26
 */
@Tag(name = "总成绩等级制分值配置WEB端", description = "总成绩等级制分值配置WEB端")
@RestController
@RequestMapping("/web/total-score-config")
@RequiredArgsConstructor
public class CourseTotalScoreConfigWebController {

    private final CourseTotalScoreConfigService courseTotalScoreConfigService;

    /**
     * 根据课程内容获取等级分制WEB配置列表
     * @param dto 初始化参数
     * @return
     */
    @GetMapping("/list")
    public R<List<CourseTotalScoreConfigResultDTO>> list(CourseTotalScoreConfigClassDTO dto) {
        return R.ok(courseTotalScoreConfigService.findCourseTotalScoreConfig(dto));
    }

    /**
     * 获取等级分值默认值
     * @return
     */
    @GetMapping("/config/default")
    public R<List<CourseTotalScoreBaseConfigEntity>> configDefault() {
        List<CourseTotalScoreBaseConfigEntity> list = courseTotalScoreConfigService.getCourseScoreDefaultConfig();
        if (list != null) {
            return R.data(list);
        } else {
            return R.fail("暂未获取到数据");
        }
    }

    /**
     * 课程内容等级制分制WEB设置接口
     * @param dto 设置
     * @return
     */
    @PostMapping("/set")
    public R<List<CourseTotalScoreConfigResultDTO>> set(@Validated @RequestBody CourseTotalScoreConfigSetDTO dto) {
        List<CourseTotalScoreConfigResultDTO> list = courseTotalScoreConfigService.setCourseTotalScoreConfig(dto);
        if (list != null) {
            return R.data(list);
        } else {
            return R.fail("设置失败");
        }
    }

    /**
     * 课程内容等级制分制WEB恢复默认接口
     * @param dto 设置
     * @return
     */
    @PostMapping("/recover")
    public R<List<CourseTotalScoreConfigResultDTO>> recover(@Validated @RequestBody CourseTotalScoreConfigClassDTO dto) {
        List<CourseTotalScoreConfigResultDTO> list = courseTotalScoreConfigService.initCourseTotalScoreConfig(dto);
        if (list != null) {
            return R.data(list);
        } else {
            return R.fail("恢复失败");
        }
    }

}
